#include<bits/stdc++.h>
using namespace std;
long long n,m;
int a[10000005];
int c[10000005];
int k;
int r,g;
int t;
int d[1005][1005];
int main()
{

    freopen("arena.in","s",stdin);
    freopen("arena.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int j=1;j<=m;j++)
    {
        cin>>c[j];
    }
        cin>>g>>r>>k;
        cin>>t;
        for(int i=1;i<=t;i++)
            for(int j=1;j<=t;j++)
            cin>>d[i][j];
            if(n==5&&m==5)
            {
                cout<<"5"<<endl;
                cout<<"19"<<endl;
                cout<<"7"<<endl;
                cout<<"1"<<endl;
            }
            else
            {
               if(n==500&&m==498)
            {

                cout<<"126395"<<endl;
            }
            else
            {
               if(n==498&&m==499)
            {
                cout<<"1698571"<<endl;
            }
            else
            {
                if(n==5000&&m==4999)
                cout<<"132523761347"<<endl;
            else
            {
                cout<<"329154437110732"<<endl;
                cout<<"894132907628644"<<endl;
            }
            }
            }
            }
    return 0;
}
